<?php
// 查看数据库中与订单和物料相关的表

// 数据库连接信息 - 使用用户提供的正确配置
$host = '127.0.0.1';
$dbname = 'scanwork';
$username = 'scanwork';
$password = 'rDezxK9h7tWp5sP7';
$port = 3306;

try {
    // 创建数据库连接
    $pdo = new PDO("mysql:host=$host;port=$port;dbname=$dbname;charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "\n=== 数据库表信息查询 ===\n\n";
    echo "正在连接数据库...\n";
    echo "数据库连接成功！\n\n";
    
    // 查询所有表名（修正SQL语法）
    $stmt = $pdo->query("SHOW TABLES WHERE Tables_in_scanwork LIKE '%order%' OR Tables_in_scanwork LIKE '%material%' OR Tables_in_scanwork LIKE '%process%' OR Tables_in_scanwork LIKE '%product%'");
    $tables = $stmt->fetchAll(PDO::FETCH_NUM);
    
    echo "找到的相关表：\n";
    foreach ($tables as $table) {
        echo "- {$table[0]}\n";
    }
    
    echo "\n=== 查询完成 ===\n";
    
} catch (PDOException $e) {
    echo "数据库连接失败：" . $e->getMessage() . "\n";
    // 尝试不指定数据库名连接，查看有哪些数据库
    try {
        $pdo_test = new PDO("mysql:host=$host;charset=utf8mb4", $username, $password); // 使用提供的密码
        $pdo_test->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        echo "\n可访问的数据库列表：\n";
        $stmt_test = $pdo_test->query("SHOW DATABASES");
        $databases = $stmt_test->fetchAll(PDO::FETCH_NUM);
        
        foreach ($databases as $db) {
            echo "- {$db[0]}\n";
        }
    } catch (PDOException $e2) {
        echo "无法连接数据库：" . $e2->getMessage() . "\n";
    }
} catch (Exception $e) {
    echo "查询出错：" . $e->getMessage() . "\n";
}

?>